﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars.Docking2010;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;


namespace ERPClient
{
    public partial class InventoryBuild : Form
    {
        public class Item
        {
            public string ID { get; set; }
            public string Name { get; set; }
            public string Unit { get; set; }
            public DateTime CreateTime { get; set; }
            public string Material { get; set; }
            public string MaterialDesc { get; set; }
            public Item()
            {
                ID = "";
                Name = "";
                Unit = "Pcs";
                CreateTime = DateTime.Now;
                Material = "";
                MaterialDesc = "";
            }
        }

        //private BindingList<Item> InsertData;

        public DocumentManager docuManager { set; get; }
        public InventoryBuild()
        {
            InitializeComponent();
            //InsertData = new BindingList<Item>();
            //InsertData.AllowEdit = true;
            //InsertData.AllowNew = true;
            //InsertData.AllowRemove = true;
            //gridControl1.DataSource = InsertData;

            //不自動調整欄寬
            gridView1.OptionsView.ColumnAutoWidth = false;
            gridView1.ScrollStyle = ScrollStyleFlags.LiveHorzScroll | ScrollStyleFlags.LiveVertScroll;
            gridView1.HorzScrollVisibility = ScrollVisibility.Always;
        }

        private void gridControl1_ProcessGridKey(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                ColumnView cv = gridControl1.FocusedView as ColumnView;
                cv.FocusedRowHandle++;
                e.Handled = true;

            }
        }

        private void button_delete_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Item t = gridView1.GetFocusedRow() as Item;
            if (gridView1.GetFocusedRowCellValue("ID") != null)
            {
                //InsertData.Remove(t);
            }
        }

        private void InventoryBuild_Load(object sender, EventArgs e)
        {
            // TODO: 這行程式碼會將資料載入 'astoolDataSet1.Inventory' 資料表。您可以視需要進行移動或移除。
            this.inventoryTableAdapter.Fill(this.astoolDataSet1.Inventory);

        }

        private void gridView1_InitNewRow(object sender, InitNewRowEventArgs e)
        {
             GridView view = sender as GridView;
             view.SetRowCellValue(e.RowHandle, view.Columns["CreateTime"], DateTime.Now);
             view.SetRowCellValue(e.RowHandle, view.Columns["Number"], 0);
        }
    }
}
